<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
	:row-style="rowStyle"
      >
        <template slot="menuLeft">
          <el-button
            type="primary"
            size="small"
            @click.stop="myAdds()"
            v-permission="permissionList.addBtn"
            >添 加</el-button
          >
          <el-button
            type="primary"
            size="small"
            @click.stop="delBatch"
            v-permission="permissionList.batchDelBtn"
            >删 除</el-button
          >
          <el-button
            type="primary"
            size="small"
            @click.stop="handleBatchSubmit"
            v-permission="permissionList.submitBtn"
            >提 交</el-button
          >
	  <el-button type="primary" size="mini" @click="submitData">加入报表差错</el-button>
          <el-button type="primary" size="small" @click.stop="myHandleExport"
            >导 出</el-button
          >

        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            icon="el-icon-edit"
            :size="scope.size"
            :type="scope.type"
            v-if="scope.row.status == '0'"
            v-permission="permissionList.editBtn"
            @click.stop="myEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-view"
            :size="scope.size"
            :type="scope.type"
            @click.stop="myView(scope.row)"
            >预览</el-button
          >
        </template>
      </avue-crud>
      <el-dialog
        width="70%"
        :visible.sync="addDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :fullscreen="changeDialogFlag"
        @closed="addClosed"
      >
        <div slot="title">
          <div>
            <span class="el-dialog__title">添 加</span>
            <div class="avue-crud__dialog__menu">
              <button
                class="el-dialog__headerbtn"
                style="margin-right:20px"
                @click.stop="changeDialog"
              >
                <i class="el-dialog__close el-icon-full-screen"></i>
              </button>
            </div>
            <button
              type="button"
              aria-label="Close"
              class="el-dialog__headerbtn"
            >
              <i class="el-dialog__close el-icon el-icon-close"></i>
            </button>
          </div>
        </div>
        <el-form :model="formAdd">
	   <avue-form
            v-model="formAdd.ticketCheck"
            :option="formOptionAdd"
          ></avue-form>
          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            单程票盘点
          </div>
          <table border="1" bordercolor="#EEEEEE">
            <tr>
              <th>项目</th>
              <th>车站票务管理室原有单程票</th>
              <th>TVM票箱单程票</th>
              <th>BOM票箱单程票</th>
              <th>AGM票箱单程票</th>
              <th>STM票箱单程票</th>
              <th>TVM废票箱单程票</th>
              <th>BOM废票箱单程票</th>
              <th>AGM废票箱单程票</th>
              <th>STM废票箱单程票</th>
              <th>车票回收箱单程票</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC清点总数</th>

              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input disabled v-model="item.scCleanNumber"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
            <tr>
              <th>实际盘点数量</th>
              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input v-model="item.realCheckNumber" @change="realCheckNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="realCheckNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>备注</th>
              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input v-model="item.remark"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>

          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            单程票压票
          </div>
          <table border="1" bordercolor="#EEEEEE">
            <tr>
              <th>项目</th>
              <th>TVM票箱压票数量</th>
              <th>BOM票箱压票数量</th>
              <th>STM票箱压票数量</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC压票总数1</th>
              <td
                v-for="(item, index) in this.formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.scCleanNumber" @change="scPressuresNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="scPressuresNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>实际压票数量</th>
              <td
                v-for="(item, index) in this.formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.realCheckNumber" @change="realPressuresNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="realPressuresNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item, index) in this.formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.remark"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>
	  <dynamic-crud
            title="营销车票"
            :data="datayx"
            :option="tableOptionAddyx"
            :isShow="oneShowYx"
            :addNew="rowNewYx"
            :rowOneButton="oneButtonYx"
            :total="yxCount"
          ></dynamic-crud>
	  <dynamic-crud
            title="应急纸票"
            :data="datayj"
            :option="tableOptionAddyj"
            :isShow="oneShowYj"
            :addNew="rowNewYj"
            :rowOneButton="oneButtonYj"
            :total="yjCount"
          ></dynamic-crud>
          <dynamic-crud
            title="特殊工作卡"
            :data="datats"
            :option="tableOptionAddts"
            :isShow="true"
            :rowOneButton="oneButtonTs"
            :total="tsCount"
          ></dynamic-crud>
          <el-row type="flex" justify="left">
            <el-col :span="18" :offset="3" style="margin-top:10px;">
              <el-form-item label="备注">
                <el-input type="textarea" :rows="5" v-model="formAdd.ticketCheck.remark"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <dynamic-crud
            title="认证工作卡2"
            v-if="false"
            :data="datarz"
            :option="tableOptionAddrz"
            :total="rzCount"
          ></dynamic-crud>
          <dynamic-crud
            title="预制单程票"
            v-if="false"
            :data="datayz"
            :option="tableOptionAddyz"
            :isShow="oneShowYz"
            :addNew="rowNewYz"
            :rowOneButton="oneButtonYz"
            :total="yzCount"
          ></dynamic-crud>
          <el-row type="flex" justify="center">
            <el-form-item>
	      <el-button type="primary" @click="confirmObj">站务人员确认</el-button>
              <el-button type="primary" size="small" @click="submitAdd">保存</el-button>
              <el-button size="small" @click="addClosed">取消</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>

      <el-dialog
        width="70%"
        :visible.sync="editDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :fullscreen="editchangeDialogFlag"
      >
        <div slot="title">
          <div>
            <span class="el-dialog__title">修 改</span>
            <div class="avue-crud__dialog__menu">
              <button
                class="el-dialog__headerbtn"
                style="margin-right:20px"
                @click.stop="editchangeDialog"
              >
                <i class="el-dialog__close el-icon-full-screen"></i>
              </button>
            </div>
            <button
              type="button"
              aria-label="Close"
              class="el-dialog__headerbtn"
            >
              <i class="el-dialog__close el-icon el-icon-close"></i>
            </button>
          </div>
        </div>
        <el-form :model="formAdd">
	 <avue-form
            v-model="formAdd.ticketCheck"
            :option="formOptionAdd"
          ></avue-form>
          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            单程票盘点
          </div>
          <table border="1" bordercolor="#EEEEEE">
            <tr>
              <th>项目</th>
              <th>车站票务管理室原有单程票</th>
              <th>TVM票箱单程票</th>
              <th>BOM票箱单程票</th>
              <th>AGM票箱单程票</th>
              <th>STM票箱单程票</th>
              <th>TVM废票箱单程票</th>
              <th>BOM废票箱单程票</th>
              <th>AGM废票箱单程票</th>
              <th>STM废票箱单程票</th>
              <th>车票回收箱单程票</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC清点总数</th>

              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input disabled v-model="item.scCleanNumber"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
            <tr>
              <th>实际盘点数量</th>
              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input v-model="item.realCheckNumber" @change="realCheckNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="realCheckNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>备注</th>
              <td v-for="(item, index) in formAdd.checkOneways" :key="index">
                <el-input v-model="item.remark"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>

          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            单程票压票
          </div>
          <table border="1" bordercolor="#EEEEEE">
            <tr>
              <th>项目</th>
              <th>TVM票箱压票数量</th>
              <th>BOM票箱压票数量</th>
              <th>STM票箱压票数量</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC压票总数2</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.scCleanNumber" @change="scPressuresNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="scPressuresNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>实际压票数量</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.realCheckNumber" @change="realPressuresNumberChange(index)"></el-input>
              </td>
              <td><el-input disabled v-model="realPressuresNumberTotal"></el-input></td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
              >
                <el-input v-model="item.remark"></el-input>
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>
          <dynamic-crud
            title="营销车票"
            :data="datayx"
            :option="tableOptionAddyx"
            :total="yxCount"
          ></dynamic-crud>
          <dynamic-crud
            title="认证工作卡1"
            v-if="false"
            :data="datarz"
            :option="tableOptionAddrz"
            :total="rzCount"
          ></dynamic-crud>
          <dynamic-crud
            title="预制单程票"
            v-if="false"
            :data="datayz"
            :option="tableOptionAddyz"
            :total="yzCount"
          ></dynamic-crud>
          <dynamic-crud
            title="应急纸票"
            :data="datayj"
            :option="tableOptionAddyj"
            :total="yjCount"
          ></dynamic-crud>
          <dynamic-crud
            title="特殊工作卡"
            :data="datats"
            :option="tableOptionAddts"
            :total="tsCount"
          ></dynamic-crud>
          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            审批内容
          </div>
          <el-form-item
            label="审核意见:"
            label-width="120px"
            style="margin-top: 20px;"
          >
            <avue-input
              type="textarea"
              v-model="formAdd.ticketCheck.abnormalNotictContent"
	      :readonly="true"
            ></avue-input>
          </el-form-item>
          <el-row type="flex" justify="left">
            <el-col :span="18" :offset="3" style="margin-top:10px;">
              <el-form-item label="备注">
                <el-input type="textarea" :rows="5" v-model="formAdd.ticketCheck.remark"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;padding: 5px 10px;"
          >
            异常原因
          </div>
          <el-form-item
            label="异常原因:"
            label-width="120px"
            style="margin-top: 20px;"
          >
            <avue-input type="textarea"></avue-input>
          </el-form-item> -->
          <el-row type="flex" justify="center">
            <el-form-item>
	      <el-button type="primary" @click="confirmObj">站务人员确认</el-button>
              <el-button type="primary" @click="editAdd">保存</el-button>
              <el-button @click="editDialogVisible = false">取消</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>

      <el-dialog
        width="70%"
        :visible.sync="viewDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :fullscreen="viewchangeDialogFlag"
      >
        <div slot="title">
          <div>
            <span class="el-dialog__title">预览</span>
            <div class="avue-crud__dialog__menu">
              <button
                class="el-dialog__headerbtn"
                style="margin-right:20px"
                @click.stop="viewchangeDialog"
              >
                <i class="el-dialog__close el-icon-full-screen"></i>
              </button>
            </div>
            <button
              type="button"
              aria-label="Close"
              class="el-dialog__headerbtn"
            >
              <i class="el-dialog__close el-icon el-icon-close"></i>
            </button>
          </div>
        </div>
        <el-form :model="formAdd">
	   <avue-form
            v-model="formAdd.ticketCheck"
            :option="formOptionView"
          ></avue-form>
          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;margin-top:4px;padding: 5px 10px;"
          >
            单程票盘点
          </div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>车站票务管理室原有单程票</th>
              <th>TVM票箱单程票</th>
              <th>BOM票箱单程票</th>
              <th>AGM票箱单程票</th>
              <th>STM票箱单程票</th>
              <th>TVM废票箱单程票</th>
              <th>BOM废票箱单程票</th>
              <th>AGM废票箱单程票</th>
              <th>STM废票箱单程票</th>
              <th>车票回收箱单程票</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC清点总数</th>

              <td
                v-for="(item, index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >
                {{ item.scCleanNumber }}
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
            <tr>
              <th>实际盘点数量</th>
              <td
                v-for="(item, index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >
                {{ item.realCheckNumber }}
              </td>
              <td>{{ realCheckNumberTotal }}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item, index) in formAdd.checkOneways"
                :key="index"
                style="text-align:center"
              >
                {{ item.remark }}
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>

          <div
            style="min-height: 36px;background: #EEEEEE;line-height:36px;margin-top:4px;padding: 5px 10px;"
          >
            单程票压票
          </div>
          <table border="1" bordercolor="#EEEEEE" width="100%">
            <tr>
              <th>项目</th>
              <th>TVM票箱压票数量</th>
              <th>BOM票箱压票数量</th>
              <th>STM票箱压票数量</th>
              <th style="width: 120px;">合计</th>
            </tr>
            <tr style="display: none">
              <th>SC压票总数3</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >
                {{ item.scCleanNumber }}
              </td>
              <td>{{ scPressuresNumberTotal }}</td>
            </tr>
            <tr>
              <th>实际压票数量</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >
                {{ item.realCheckNumber }}
              </td>
              <td>{{ realPressuresNumberTotal }}</td>
            </tr>
            <tr>
              <th>备注</th>
              <td
                v-for="(item, index) in formAdd.checkOnewayPressures"
                :key="index"
                style="text-align:center"
              >
                {{ item.remark }}
              </td>
              <td><el-input disabled></el-input></td>
            </tr>
          </table>
           <dynamic-crud
            title="营销车票"
            :data="datayx"
            :option="tableOptionViewyx"
            :button="false"
            :total="yxCount"
          ></dynamic-crud>
	  <dynamic-crud
            title="应急纸票"
            :data="datayj"
            :option="tableOptionViewyj"
            :button="false"
            :total="yjCount"
          ></dynamic-crud>
          <dynamic-crud
            title="特殊工作卡"
            :data="datats"
            :option="tableOptionViewts"
            :button="false"
            :total="tsCount"
          ></dynamic-crud>
          <dynamic-crud
            title="认证工作卡3"
            v-if="false"
            :data="datarz"
            :option="tableOptionViewrz"
            :button="false"
            :total="rzCount"
          ></dynamic-crud>
          <dynamic-crud
            title="预制单程票"
            v-if="false"
            :data="datayz"
            :option="tableOptionViewyz"
            :button="false"
            :total="yzCount"
          ></dynamic-crud>

          <el-row type="flex" justify="left">
            <el-col :span="6" :offset="6" style="margin-top:10px;"
              >审批状态：{{ this.status }}</el-col
            >
          </el-row>
          <el-row type="flex" justify="left">
            <el-col :span="6" :offset="6" style="margin-top:10px;"
              >审批意见：{{
                this.formAdd.ticketCheck.abnormalNotictContent
              }}</el-col
            >
          </el-row>
          <el-row type="flex" justify="left">
            <el-col :span="18" :offset="3" style="margin-top:10px;">
              <el-form-item label="备注">
                <el-input type="textarea" :rows="5" v-model="formAdd.ticketCheck.remark" readonly></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row type="flex" justify="center">
            <el-form-item>
              <el-button @click="viewDialogVisible = false">返回</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-dialog>
    </basic-container>
    <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
  </div>
</template>

<script>
import baseCrud from "@/mixins/base-crud";
import {
  getObj,
  addObj,
  putObj,
  delsObj,
  approvalObj,getTypeValue,getTicketCheck,
  exportExcel,
  fetchList
} from "@/api/subwaystm/swstticketcheck";
import { getDict,getDictByRP } from "@/api/support/swpmticketcardtypeparam";
import {
  formOptionAdd,
  tableOptionAddts,
  tableOptionAddyj,
  tableOptionAddyx,
  tableOptionAddyz,
  tableOptionAddrz
} from "@/const/crud/subwaystm/swstticket/addandedit/swstticketcheckAdd";
import {
  formOptionView,
  tableOptionViewts,
  tableOptionViewyj,
  tableOptionViewyx,
  tableOptionViewyz,
  tableOptionViewrz
} from "@/const/crud/subwaystm/swstticket/view/swstticketcheckView";
import request from "@/router/axios";
import {startDate, endDate} from "@/const/crud/subwaystm/swstticketcheck";
import { mapGetters } from "vuex";
import { dateFormat } from "@/util/date";
import { handleExcelResponse } from "@/util/util";
import addReportEditor from '@/views/stationTiecketManager/xianWngCJXXQR/BBCCGG/BBCCGGSQ/Editor';
import transitUtil from "@/api/subwayRat/transitUtil";
import { checkPwd,checkPwdByAccount } from "@/api/admin/user";

export default {
  name: "swstticketcheck",
  mixins: [baseCrud("subwaystm/swstticketcheck")],
  components: {
    addReportEditor
  },
  data() {
    return {
      searchForm: {
        dates1: [startDate, endDate]
      },
      datats: [],
      datarz: [],
      datayz: [],
      datayj: [],
      datayx: [],
      // 预制单程票
      oneShowYz: true,
      rowNewYz: true,
      yzDictData: [],
      // 应急纸票
      oneShowYj: true,
      rowNewYj: true,
      yjDictData: [],
      // 营销车票
      oneShowYx: true,
      rowNewYx: true,
      yxDictData: [],
      addDialogVisible: false,
      formOptionAdd: formOptionAdd,
      tableOptionAddts: tableOptionAddts,
      tableOptionAddrz: tableOptionAddrz,
      tableOptionAddyj: tableOptionAddyj,
      tableOptionAddyz: tableOptionAddyz,
      tableOptionAddyx: tableOptionAddyx,
      formOptionView: formOptionView,
      tableOptionViewts: tableOptionViewts,
      tableOptionViewrz: tableOptionViewrz,
      tableOptionViewyj: tableOptionViewyj,
      tableOptionViewyz: tableOptionViewyz,
      tableOptionViewyx: tableOptionViewyx,
      changeDialogFlag: false,
      editDialogVisible: false,
      editchangeDialogFlag: false,
      viewDialogVisible: false,
      viewchangeDialogFlag: false,
      dateFormat: dateFormat,
      status: "",
      formAdd: {
        ticketCheck: {},
        checkOneways: [],
        checkOnewayPressures: [],
        workCards: [],
        workCardsRz: [],
        checkGeneralsYZ: [],
        checkGeneralsYJ: [],
        checkMarketings: [],
        checkGenerals: []
      },
      checkDay:25,
      checkData: {},
      // 实际盘点数量合计
      realCheckNumberTotal: 0,
      // SC压票合计
      scPressuresNumberTotal: 0,
      // 实际压票数量合计
      realPressuresNumberTotal: 0,
      //站务员密码确认标识
      saveFlag: false
    };
  },
  created() {
    this.delBatch_btn = this.permissions["swstticketcheck_batch_del"];
    this.submitBatch_btn = this.permissions[
      "stm_swstapplynetworkcheckpassengeraffairs_submitBatch"
    ];
    // 预制单程票
    getDict("YZDCP").then(res => {
      this.yzDictData = res.data.data;
    });
    // 应急纸票
    getDict("YJZP").then(res => {
      this.yjDictData = res.data.data;
    });
    // 营销车票
    getDictByRP().then(res => {
      this.yxDictData = res.data.data;
    });
    getTypeValue('check_day').then(response => {
      this.checkDay = parseInt(response.data.data[0].value);
      let now = new Date();
	  });
    this.otherVueAction();
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.swstticketcheck_add, false),
        delBtn: this.vaildData(this.permissions.swstticketcheck_del, false),
        batchDelBtn: this.vaildData(
          this.permissions.swstticketcheck_batch_del,
          false
        ),
        editBtn: this.vaildData(this.permissions.swstticketcheck_edit, false),
        submitBtn: this.vaildData(
          this.permissions.swstticketcheck_approval_status,
          false
        )
      };
    },
    tsCount: function() {
      return this.datats.length;
    },
    rzCount: function() {
      return this.datarz.length;
    },
    yzCount: function() {
      let count = 0;
      for (const item of this.datayz) {
        count += Number(item.ticketNum || 0);
      }
      return count;
    },
    yjCount: function() {
      let count = 0;
      for (const item of this.datayj) {
        count += Number(item.ticketNum || 0);
      }
      return count;
    },
    yxCount: function() {
      let count = 0;
      for (const item of this.datayx) {
        count += Number(item.ticketNum || 0);
      }
      return count;
    }
  },
  methods: {
    rowStyle({ row, column, rowIndex }) {
      if (row.status == "0") {
        return {
          backgroundColor: "#eee",
          color: "red",
        };
      }
    },
    // searchChange(form, done) {
    //   // console.log(form)
    //   // //startDate, endDate
    //   // if(form!=null && form.checkTime != null){
    //   //   this.searchForm.dates1 = form.checkTime
    //   // } else {
    //   //   this.searchForm.dates1 = null
    //   // }
    // window.location.reload();
    //   this.getList(this.page, this.searchForm).then(() => {
    //     done();
    //   });
    // },
    //加入报表差错
    async submitData() {
        if (this.$refs.crud.tableSelect.length < 1) {
          this.$message.error("请选择数据");
          return false;
        }
        if (this.$refs.crud.tableSelect.length != 1) {
          this.$message.error("只能选择一条数据");
          return false;
        }
        let res = false;
        let ress = false;
        for (const table of this.$refs.crud.tableSelect) {
          if (table.status != "1") {
            this.$message.error("请选择已提交的数据");
            return false;
          }else{
            if (table.isAddReprotError == "1") {
              res = await this.$confirm('该数据已加入报表差错，是否重新加入？', '提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'warning'
              });
              if (!res) {
                return;
              }else{
                ress = true;
              }
            }
          }
        }
        if(res==false){
          ress = await this.$confirm("是否加入报表差错", "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          });
        }
        if (!ress) {
          return;
        }
        this.selectKeys = this.$refs.crud.tableSelect;
        let param={
          dialogTitle: "加入报表差错",
          diffAmountId:this.selectKeys[0].id,
          dataSourceTable:"sw_st_ticket_check",
          lineCode:this.selectKeys[0].lineCode,
          stationCode:this.selectKeys[0].stationCode,
          reprotTime:this.selectKeys[0].checkTime,
          reportNameId:14,
          settleBeginTime:this.selectKeys[0].checkTime,
          settleEndTime:this.selectKeys[0].checkTime,
	  userCodes:this.selectKeys[0].conductorJobNo,
	  dutyStationLeaderCode: this.selectKeys[0].workPersonJobNo, 
	  dutyStationLeaderName: this.selectKeys[0].workPersonName, 
          showType:3,
          dataSource:1
        };
        this.$refs.addReportEditor.others_report_add_call(param);
      },
    async myHandleExport(){
      let loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      })
      try {
        let tableSelect = this.$refs.crud.tableSelect;
        let ids = tableSelect.map(row => row.id)
        let param = {
          ids: this.validatenull(ids)?null:ids
        };
        const res = await exportExcel(param);
        handleExcelResponse(res);
      } finally {
        loading.close();
      }
    },
    oneButtonTs: function(callback) {
      callback({});
      callback({});
      callback({});
    },
    addClosed: function() {
      this.tableOptionAddyx.column[0].cell = true;
      this.tableOptionAddyj.column[0].cell = true;
      this.tableOptionAddyz.column[0].cell = true;
      this.addDialogVisible = false;
      this.rowNewYx = true;
      this.rowNewYj = true;
    },
    // 预制单程票
    oneButtonYz: function(callback) {
      this.rowNewYz = false;
      this.tableOptionAddyz.column[0].cell = false;
      if (this.datayz.length > 0) {
        this.$confirm("此操作将重新生成, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          for (const item of this.datayz) {
            Object.keys(item).map(key => {
              if (key != "$cellEdit" && key != "ticketName") {
                item[key] = undefined;
              }
            });
          }
        });
      } else {
        for (const item of this.yzDictData) {
          const obj = {
            ticketName: item.id,
            ticketNum: 0,
          };
          callback(obj);
        }
      }
    },
    //报表差错加载
    otherVueAction(){
      transitUtil.$on('updateReport_call_14',(param)=>{
        //alert("获取查询条件333-otherVueAction---"+JSON.stringify(param))
        let p=param;

        // if(param!=null && param.ticketTypeEn!=''){
        //   this.searchForm.ticketTypeEn = param.ticketTypeEn;
        // }
        // if(param!=null && param.ticketTypeParamEn!=''){
        //   this.searchForm.ticketTypeParamEn = param.ticketTypeParamEn;
        // }
        this.searchForm.checkTimeStr = param.checkTimeStr;
        fetchList(Object.assign({
          current: this.page.currentPage,
          size: this.page.pageSize
        }, p)).then(response => {
          this.tableData = response.data.data.records
          this.page.total = response.data.data.total
          this.tableLoading = false
        })
      });
    },

    oneButtonYj: function(callback) {
      this.rowNewYj = false;
      this.tableOptionAddyj.column[0].cell = false;
      if (this.datayj.length > 0) {
        this.$confirm("此操作将重新生成, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          for (const item of this.datayj) {
            Object.keys(item).map(key => {
              if (key != "$cellEdit" && key != "ticketName") {
                item[key] = undefined;
              }
            });
          }
        });
      } else {
        for (const item of this.yjDictData) {
          const obj = {
            ticketName: item.id
          };
          callback(obj);
        }
      }
    },
     //一键新增重新生成时，需要删除原有的数据
    delEditRow() {
     this.datayx.forEach(row => {
        let index = this.datayx.indexOf(row);
	this.datayx.splice(index, this.datayx.length);
      });
    },
    oneButtonYx: function(callback) {
      this.rowNewYx = false;
      this.tableOptionAddyx.column[0].cell = false;
      if (this.datayx.length > 0) {
        this.$confirm("此操作将重新生成, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.delEditRow();
	  for (const item of this.yxDictData) {
            const obj = {
                ticketName: item.subEnName,
                ticketTimes: item.ticketCount,
                ticketPrice: item.ticketAmount
             };
            callback(obj);
          }
	  /*for (const item of this.datayx) {
            Object.keys(item).map(key => {
              if (
                key != "$cellEdit" &&
                key != "ticketName" &&
                key !== "ticketTimes" &&
                key !== "ticketPrice"
              ) {
                item[key] = undefined;
              }
            });
          }*/
        }).catch(() => {
          this.rowNewYx = true;
        });
      } else {
        for (const item of this.yxDictData) {
          const obj = {
            ticketName: item.subEnName,
            ticketTimes: item.ticketTimes,
            ticketPrice: item.ticketPrice
          };
          callback(obj);
        }
      }
    },
    delBatch: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.info("请选择要删除的记录");
        return false;
      }
      let ids = [];
      for (const id of this.$refs.crud.tableSelect) {
        if (id.status != 0) {
          this.$message.error("只能删除未提交的数据！");
          return false;
        }
        if (id.isAddReprotError != '0') {
          this.$message.error("只能删除未加入报表差错的数据！");
          return false;
        }
        ids.push(id.id);
      }
      delsObj(ids);
      this.$confirm("确定删除吗？")
        .then(data => {
          this.$message.success("删除成功");
          this.getList(this.page);
          done();
        })
        .catch(() => {
          loading();
        });
    },
    handleBatchSubmit() {
      var tableSelect = this.$refs.crud.tableSelect;
      if (tableSelect.length == 0) {
        this.$message.info("请选择要提交的记录");
        return;
      }
      for (const item of tableSelect) {
        if (item.status != 0 && item.status != 3) {
          this.$message.error("请重新选择数据！");
          this.$refs.crud.toggleSelection();
          return false;
        }
      }
      var ids = tableSelect.map(row => row.id);
      const params = {
        ids: ids.join(","),
        status: "1"
      };
      approvalObj(params).then(response => {
        this.$message.success("提交成功");
        this.getList(this.page);
      });
    },
    /* 20241227
    async getTicketCheck(){
      let now = new Date();
      let date = dateFormat(now).substr(0, 8)+ this.checkDay;
      await getTicketCheck(date)
        .then(response => {
          this.checkData = response.data.data;
        })
    },*/
    myAdds(){
      this.realCheckNumberTotal = 0;
      this.scPressuresNumberTotal = 0;
      this.realPressuresNumberTotal = 0;
      /*
      this.checkData = {};
      this.getTicketCheck().then(response =>{
        if(!this.validatenull(this.checkData)){
          this.$message.error("本月盘点数据已录入，请勿重复录入！");
          return false;
        }
        this.myAdd();
      });*/
      this.myAdd();
      this.saveFlag = false;//密码验证标识重置

    },
    myAdd() {
      for (var i in this.formAdd.ticketCheck) {
        this.formAdd.ticketCheck[i] = null;
      }
      let now = new Date();
      this.formAdd.ticketCheck.checkTime = dateFormat(now);
      this.formAdd.checkOneways = [
        {
          ticketType: "0",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "1",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "2",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "3",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "4",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "5",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "6",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "7",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "8",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        },
        {
          ticketType: "9",
          scCleanNumber: "",
          realCheckNumber: "",
          remark: ""
        }
      ];
      this.formAdd.checkOnewayPressures = [
        {
          ticketType: "0",
          scCleanNumber: "",
          realCheckNumber: "",
          totalNumber: "",
          remark: ""
        },
        {
          ticketType: "1",
          scCleanNumber: "",
          realCheckNumber: "",
          totalNumber: "",
          remark: ""
        },
        {
          ticketType: "2",
          scCleanNumber: "",
          realCheckNumber: "",
          totalNumber: "",
          remark: ""
        }
      ];
      this.datayz = [];
      this.datayj = [];
      this.datayx = [];
      this.datats = [];
      this.datarz = [];
      this.addDialogVisible = true;
    },
    myEdit: function(row) {
      this.realCheckNumberTotal = 0;
      this.scPressuresNumberTotal = 0;
      this.realPressuresNumberTotal = 0;
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          let workCardsMy = [];
          let workCardsRzMy = [];
          for (const item of res.workCards) {
            if (item.ticketType == "0") {
              workCardsMy.push(item);
            } else {
              workCardsRzMy.push(item);
            }
          }
          this.datats = workCardsMy;
          for (const item of this.datats) {
            item.$cellEdit = true;
          }
          this.datarz = workCardsRzMy;
          for (const item of this.datarz) {
            item.$cellEdit = true;
          }
          let checkGeneralsYZMy = [];
          let checkGeneralsYJMy = [];
          for (const item of res.checkGenerals) {
            if (item.ticketType == "0") {
              checkGeneralsYZMy.push(item);
            } else {
              checkGeneralsYJMy.push(item);
            }
          }
          this.datayz = checkGeneralsYZMy;
          for (const item of this.datayz) {
            item.$cellEdit = true;
          }
          this.datayj = checkGeneralsYJMy;
          for (const item of this.datayj) {
            item.$cellEdit = true;
          }
          this.datayx = res.checkMarketings;
          for (const item of this.datayx) {
            item.$cellEdit = true;
          }
          this.formAdd.checkOnewayPressures = res.checkOnewayPressures;
          this.formAdd.checkOneways = res.checkOneways;
          this.formAdd.ticketCheck = res.ticketCheck;
        })
        .then(() => {
          // 初始化合计值
          this.realCheckNumberChange();
          this.scPressuresNumberChange();
          this.realPressuresNumberChange();
          this.editDialogVisible = true;
        });
	this.saveFlag = false;
    },
    myView: function(row) {
      this.realCheckNumberTotal = 0;
      this.scPressuresNumberTotal = 0;
      this.realPressuresNumberTotal = 0;
      this.status = row.$status;
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          let workCardsMy = [];
          let workCardsRzMy = [];
          for (const item of res.workCards) {
            if (item.ticketType == "0") {
              workCardsMy.push(item);
            } else {
              workCardsRzMy.push(item);
            }
          }
          this.datats = workCardsMy;
          this.datarz = workCardsRzMy;
          let checkGeneralsYZMy = [];
          let checkGeneralsYJMy = [];
          for (const item of res.checkGenerals) {
            if (item.ticketType == "0") {
              checkGeneralsYZMy.push(item);
            } else {
              checkGeneralsYJMy.push(item);
            }
          }
          this.datayz = checkGeneralsYZMy;
          this.datayj = checkGeneralsYJMy;
          this.datayx = res.checkMarketings;
          this.formAdd.checkOnewayPressures = res.checkOnewayPressures;
          this.formAdd.checkOneways = res.checkOneways;
          this.formAdd.ticketCheck = res.ticketCheck;
        })
        .then(() => {
        // 初始化合计值
        this.realCheckNumberChange();
        this.scPressuresNumberChange();
        this.realPressuresNumberChange();
          this.viewDialogVisible = true;
        });
	this.saveFlag = false;
    },

    editAdd: function(done) {
       if(this.formAdd.ticketCheck.checkTime == null || this.formAdd.ticketCheck.checkTime == "" || this.formAdd.ticketCheck.checkTime == undefined){
        this.$message.info(
          "请选择盘点时间！"
        );
        return;
      }
      for (const item of this.formAdd.checkOneways) {
        // if (this.validatenull(item.scCleanNumber)) {
        //   this.$message.info("单程票盘点模块SC清点总数一行为必填项！不能为空");
        //   return;
        // } else {
        //   if (isNaN(Number(item.scCleanNumber))) {
        //     this.$message.info("SC清点总数只能输入数字！");
        //     return;
        //     console.log()
        //   }
        // }
        if (this.validatenull(item.realCheckNumber)) {
          this.$message.info(
            "单程票盘点模块实际盘点数量一行为必填项！不能为空"
          );
          return;
        } else {
          if (isNaN(Number(item.realCheckNumber))) {
            this.$message.info("实际盘点数量只能输入数字！");
            return;
          }
        }
      }
      for (const item of this.formAdd.checkOnewayPressures) {
        // if (this.validatenull(item.scCleanNumber)) {
        //   this.$message.info("单程票压票模块SC压票总数一行为必填项！不能为空");
        //   return;
        // } else {
        //   if (isNaN(Number(item.scCleanNumber))) {
        //     this.$message.info("SC压票总数只能输入数字！");
        //     return;
        //   }
        // }
        if (this.validatenull(item.realCheckNumber)) {
          this.$message.info(
            "单程票压票模块实际压票数量一行为必填项！不能为空"
          );
          return;
        } else {
          if (isNaN(Number(item.realCheckNumber))) {
            this.$message.info("实际压票数量只能输入数字！");
            return;
          }
        }
      }
      if (
        this.datats.length == 0 &&
        this.datarz.length == 0 &&
        this.datayz.length == 0 &&
        this.datayj.length == 0
      ) {
        this.$message.info(
          // "特殊工作卡、认证工作卡、预制单程票、应急纸票必填一项！"
          "特殊工作卡、应急纸票必填一项！"
        );
        return;
      } else {
        if (this.datats.length > 0) {
          for (const item of this.datats) {
            if (item.cardOrder == null) {
              this.$message.info("请输入卡号！");
              return;
            }
          }
        } else if (this.datarz.length > 0) {
          for (const item of this.datarz) {
            if (item.cardOrder == null) {
              this.$message.info("请输入卡号！");
              return;
            }
          }
        } else if (this.datayz.length > 0) {
          for (const item of this.datayz) {
            if (item.ticketName == null || item.ticketNum == null) {
              this.$message.info("请输入车票名称和张数！");
              return;
            }
          }
        } else {
          if (this.datayj.length > 0) {
            for (const item of this.datayj) {
              if (item.ticketName == null || item.ticketNum == null) {
                this.$message.info("请输入车票名称和张数！");
                return;
              }
            }
          }
        }
      }
      if (!this.saveFlag) {
        this.$message.error("请先点击站务人员确认按钮进行确认！");
        return false;
      }
      this.datats.forEach(d => (d.ticketType = 0));
      this.datarz.forEach(d => (d.ticketType = 1));
      this.formAdd.workCards = this.datats.concat(this.datarz);
      this.datayz.forEach(d => (d.ticketType = 0));
      this.datayj.forEach(d => (d.ticketType = 1));
      this.formAdd.checkGenerals = this.datayz.concat(this.datayj);
      this.formAdd.checkMarketings = this.datayx;
      this.formAdd.ticketCheck.checkTime = this.formAdd.ticketCheck.checkTime;
      console.log(this.formAdd);
      this.$confirm("请确认盘点日期", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
      putObj(this.formAdd)
        .then(data => {
          this.$message.success("修改成功");
          this.editDialogVisible = false;
          this.getList(this.page);
          done();
        })
        .catch(() => {});
        })
    },
    //售票员账号密码确认
    confirmObj() {
      if (this.validatenull(this.formAdd.ticketCheck.conductorJobNo)) {
        this.$message.error("请选择站务人员！");
        return;
      }
      this.$prompt("请输入站务人员密码", "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputType: "password",
        inputValidator: (val) => {
          if (!val) return "请输入密码";
        },
      })
        .then(({ value }) => {
          return checkPwd(this.formAdd.ticketCheck.conductorJobNo, value);
        })
        .then((response) => {
          var result = response.data.data;
          if (result) {
            this.$message.success("确认成功");
            this.saveFlag = true;
            return;
          } else {
            this.$message.error("密码错误");
	    this.saveFlag = false;
            return Promise.reject("密码错误");
          }
        })
        .catch((error) => {
          this.saveFlag = false;
        });
    },
    submitAdd: function(done) {
     if(this.formAdd.ticketCheck.checkTime == null || this.formAdd.ticketCheck.checkTime == "" || this.formAdd.ticketCheck.checkTime == undefined){
          this.$message.error(
            "请选择盘点时间！"
          );
          return;
      }
      if(this.formAdd.ticketCheck.conductorName == null || this.formAdd.ticketCheck.conductorName == "" || this.formAdd.ticketCheck.conductorName == undefined){
          this.$message.error(
            "请选择站务人员！"
          );
          return;
      }
      for (const item of this.formAdd.checkOneways) {
        // if (item.scCleanNumber == "") {
        //   this.$message.info("单程票盘点模块SC清点总数一行为必填项！不能为空");
        //   return;
        // } else {
        //   if (isNaN(Number(item.scCleanNumber))) {
        //     this.$message.info("SC清点总数只能输入数字！");
        //     return;
        //   }
        // }
        if (item.realCheckNumber == "") {
          this.$message.info(
            "单程票盘点模块实际盘点数量一行为必填项！不能为空"
          );
          return;
        } else {
          if (isNaN(Number(item.realCheckNumber))) {
            this.$message.info("实际盘点数量只能输入数字！");
            return;
          }
        }
      }
      for (const item of this.formAdd.checkOnewayPressures) {
        // if (item.scCleanNumber == "") {
        //   this.$message.info("单程票压票模块SC压票总数一行为必填项！不能为空");
        //   return;
        // } else {
        //   if (isNaN(Number(item.scCleanNumber))) {
        //     this.$message.info("SC压票总数只能输入数字！");
        //     return;
        //   }
        // }
        if (item.realCheckNumber == "") {
          this.$message.info(
            "单程票压票模块实际压票数量一行为必填项！不能为空"
          );
          return;
        } else {
          if (isNaN(Number(item.realCheckNumber))) {
            this.$message.info("实际压票数量只能输入数字！");
            return;
          }
        }
      }
      if (
        this.datats.length == 0 &&
        this.datarz.length == 0 &&
        this.datayz.length == 0 &&
        this.datayj.length == 0
      ) {
        this.$message.info(
          // "特殊工作卡、认证工作卡、预制单程票、应急纸票必填一项！"
          "特殊工作卡、应急纸票必填一项！"
        );
        return;
      } else {
        if (this.datats.length > 0) {
          for (const item of this.datats) {
            if (item.cardOrder == null) {
              this.$message.info("请输入卡号！");
              return;
            }
          }
        } else if (this.datarz.length > 0) {
          for (const item of this.datarz) {
            if (item.cardOrder == null) {
              this.$message.info("请输入卡号！");
              return;
            }
          }
        } else if (this.datayz.length > 0) {
          for (const item of this.datayz) {
            if (item.ticketName == null || item.ticketNum == null) {
              this.$message.info("请输入车票名称和张数！");
              return;
            }
          }
        } else {
          if (this.datayj.length > 0) {
            for (const item of this.datayj) {
              if (item.ticketName == null || item.ticketNum == null) {
                this.$message.info("请输入车票名称和张数！");
                return;
              }
            }
          }
        }
      }
      if (!this.saveFlag) {
        this.$message.error("请先点击站务人员确认按钮进行确认！");
        return false;
      }
      this.datats.forEach(d => (d.ticketType = 0));
      this.datarz.forEach(d => (d.ticketType = 1));
      this.formAdd.workCards = this.datats.concat(this.datarz);
      this.datayz.forEach(d => (d.ticketType = 0));
      this.datayj.forEach(d => (d.ticketType = 1));
      this.formAdd.checkGenerals = this.datayz.concat(this.datayj);
      this.formAdd.checkMarketings = this.datayx;
      this.formAdd.checkOnewayPressures = this.formAdd.checkOnewayPressures;
      this.formAdd.checkOneways = this.formAdd.checkOneways;
      //this.formAdd.ticketCheck.checkTime = dateFormat(new Date());
      //let now = new Date();
      //this.formAdd.ticketCheck.checkTime = dateFormat(now).substr(0, 8) + this.checkDay + dateFormat(now).substr(10, 19);
      this.formAdd.ticketCheck.checkTime = this.formAdd.ticketCheck.checkTime;

     this.$confirm("请确认盘点日期", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
      addObj(this.formAdd)
        .then(data => {
          this.$message.success("添加成功");
          this.addDialogVisible = false;
          this.getList(this.page);
          done();
        })
        .catch(() => {});
        })
    },
    changeDialog: function() {
      if (this.changeDialogFlag) {
        this.changeDialogFlag = false;
      } else {
        this.changeDialogFlag = true;
      }
    },
    editchangeDialog: function() {
      if (this.editchangeDialogFlag) {
        this.editchangeDialogFlag = false;
      } else {
        this.editchangeDialogFlag = true;
      }
    },
    viewchangeDialog: function() {
      if (this.viewchangeDialogFlag) {
        this.viewchangeDialogFlag = false;
      } else {
        this.viewchangeDialogFlag = true;
      }
    },
    // 更新实际盘点数量合计值
    realCheckNumberChange(index) {
      this.realCheckNumberTotal = this.formAdd.checkOneways.reduce((acc, item) => acc + (parseFloat(item.realCheckNumber) || 0), 0);
    },
    // 更新SC压票总数合计值
    scPressuresNumberChange(index) {
      this.scPressuresNumberTotal = this.formAdd.checkOnewayPressures.reduce((acc, item) => acc + (parseFloat(item.scCleanNumber) || 0), 0);
    },
    // 更新实际压票数量合计值
    realPressuresNumberChange(index) {
      this.realPressuresNumberTotal = this.formAdd.checkOnewayPressures.reduce((acc, item) => acc + (parseFloat(item.realCheckNumber) || 0), 0);
    }
  }
};
</script>

<style>
tr th:first-child {
  width: 93px;
}
tr th {
  color: rgba(0, 0, 0, 0.85);
  background-color: #fafafa;
  text-align: center;
  font-size: 12px;
  padding: 8px 5px;
}
tr th td {
  color: #dcdfe6;
}
table {
  width: 100%;
}
</style>
